package com.spring.sunflower.common

import android.view.WindowManager
import com.spring.sunflower.R
import com.spring.sunflower.base.BaseCompatActivity
import com.spring.sunflower.constant.Constant
import com.spring.sunflower.widget.FixViewPager

/**
 * Created by Kevin on 2021/8/2<br/>
 *
 * Describe:<br/>
 */
class PhotoViewerActivity : BaseCompatActivity() {
    private var mViewPager: FixViewPager? = null
    private var mAdapter: PhotoAdapter? = null

    override fun doSomethingBeforeOnCreate() {
        super.doSomethingBeforeOnCreate()
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
    }

    override fun getLayoutID(): Int = R.layout.activity_photo_viewer
    override fun initView() {
        val photoList = intent.getStringArrayListExtra(Constant.PHOTO_LIST_VIEWER)
        val currentPos = intent.getIntExtra(Constant.PHOTO_CURRENT_POSITION, 0)
        mViewPager = findViewById(R.id.viewpager)
        mAdapter = PhotoAdapter(this, photoList)
        mViewPager?.let {
            it.adapter = mAdapter
            it.currentItem = currentPos
        }
        mAdapter?.setOnPhotoClickListener(object : PhotoAdapter.OnPhotoClickListener {
            override fun onPhotoClick(position: Int) {
                onBackPressed()
            }

            override fun onPhotoLongClick(position: Int) {
            }

        })
    }
}